package com.th.utils;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Random;

@Component
public class SendMessage {
   @Autowired
    private JavaMailSenderImpl mailSender;

    public  String contextLoads(String email) throws MessagingException {
//        int count = 1;//默认发送一次
//        MimeMessage mimeMessage = mailSender.createMimeMessage();
//        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
//        String codeNum = "";
//        while (count-- != 0) {
//
//            int[] code = new int[3];
//            Random random = new Random();
//            //自动生成验证码
//            for (int i = 0; i < 6; i++) {
//                int num = random.nextInt(10) + 48;
//                int uppercase = random.nextInt(26) + 65;
//                int lowercase = random.nextInt(26) + 97;
//                code[0] = num;
//                code[1] = uppercase;
//                code[2] = lowercase;
//                codeNum += (char) code[random.nextInt(3)];
//            }
//            System.out.println(codeNum);
//            //标题
//            helper.setSubject("您的验证码为：" + codeNum);
//            //内容
//            helper.setText("您好！您的验证码为：" + "<h2>" + codeNum + "</h2>" + "千万不能告诉别人哦！", true);
//            //邮件接收者
//            helper.setTo(email);
//            //邮件发送者，必须和配置文件里的一样，不然授权码匹配不上
//            helper.setFrom("641773579@qq.com");
//            mailSender.send(mimeMessage);
//            System.out.println("邮件发送成功！" + (count + 1));
//        }
        String test="1234";
       // return codeNum;
        return test;
    }
}
